﻿Imports CommandConsoleFramework

Module Module1
    Sub Main()
        CommandInterpreter.DefaultCommands = New TestDefaultCommands
        CommandInterpreter.Run()
    End Sub

    <CommandMethod("Counts", "", "Count")>
    <CommandMethodArgument("Number", 0, "The number to count up to.")>
    Public Sub CountTo(line As CommandLine)
        If line.ArgumentString.Length > 0 Then
            Dim max As Integer
            If Integer.TryParse(line.ArgumentString.Trim, max) Then
                For i As Integer = 1 To max
                    ConsoleOutput.WriteIndented(5, True, i.ToString)
                Next
            Else
                line.SetResultMessage("Invalid number: " & line.ArgumentString, True)
            End If
        Else
            line.SetResultMessage("Count to what?")
        End If
    End Sub

    <CommandMethod()>
    Public Sub Menu(line As CommandLine)
        Dim menuItems() As String = New String() {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Tewleve",
                                                 "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen", "Twenty", "Twenty One",
                                                 "Twenty Two", "Twenty Three", "Twenty Four", "Twenty Five", "Twenty Six", "Twenty Seven", "Twenty Eight", "Twenty Nine", "Thirty", "Thirty One",
                                                 "Thirty Two", "Thirty Three", "Thirty Four", "Thirty Five", "Thirty Six", "Thirty Seven", "Thirty Eight", "Thirty Nine", "Fourty"}
        Dim result As ConsoleInputMenuSelection = ConsoleInput.GetMenuSelection("A Test Menu", menuItems)
        line.SetResultMessage(result.MenuNumber & " - " & result.MenuItemName & " - " & result.SourceIndex)
    End Sub

    <CommandMethod()>
    Public Sub Hello(line As CommandLine)
        line.SetResultMessage("Hello, " & ConsoleInput.GetTextResponse("What is your name?"))
    End Sub

    <CommandMethod()>
    Public Sub Number(line As CommandLine)
        line.SetResultMessage(String.Format("Number is: {0:n2}", ConsoleInput.GetDecimalResponse("Enter a Number:")))
    End Sub

    <CommandMethod()>
    Public Sub Question(line As CommandLine)
        If ConsoleInput.GetYesNoResponse("Do you want to?") Then
            line.SetResultMessage("Alright.")
        Else
            line.SetResultMessage("Fine.")
        End If
    End Sub
End Module

Public NotInheritable Class TestDefaultCommands
    Inherits DefaultCommands

    <CommandMethod(True)>
    Overrides Sub Echo(line As CommandConsoleFramework.CommandLine)
        line.SetResultMessage("Not Implemented", True)
    End Sub
End Class

'AddHandler CommandInterpreter.ProcessCommandLine, AddressOf CommandInterpreter_ProcessCommandLine
'Private Sub CommandInterpreter_ProcessCommandLine(send As Object, e As ProcessCommandLineEventArgs)
'    If e.Line.CommandName = "?" Then
'        e.Line.CommandName = "help"
'        e.HandledByCommandMethod = True
'    ElseIf e.Line.CommandName = "test" Then
'        e.Line.SetResultMessage("1...2...3...")
'        e.HandledByCustom = True
'    End If
'End Sub

'Private _ExampleWorker As New ExampleWorkerClass
'CommandInterpreter.Registration.RegisterMethod(AddressOf TestFoo, New CommandMethodArgumentAttribute("another", 3, "another test"))
'CommandInterpreter.Registration.RegisterMethod(AddressOf TestFoo, New CommandMethodArgumentAttribute("another", 3, "another test"))
'CommandInterpreter.Registration.RegisterObject(_ExampleWorker)

'<CommandMethodArgument("test1", 0, "this is a test")>
'<CommandMethodArgument("test2", 1, "this is a test")>
'<CommandMethodArgument("test3", 2, "this is a test")>
'Private Sub TestFoo(line As CommandLine)
'    line.SetResultMessage("This was a local command.", False)
'End Sub

'Private Sub NoHelp(line As CommandLine)
'    line.SetResultMessage("This command has no help!")
'End Sub

'<CommandMethod()>
'<CommandMethodArgument("Number", 0, "The number to count up to.")>
'Public Sub CountTo(line As CommandLine)
'    If line.ArgumentString.Length > 0 Then
'        Dim max As Integer
'        If Integer.TryParse(line.ArgumentString.Trim, max) Then
'            For i As Integer = 1 To max
'                ConsoleOutput.WriteIndented(5, True, i.ToString)
'            Next
'        Else
'            line.SetResultMessage("Invalid number: " & line.ArgumentString, True)
'        End If
'    Else
'        line.SetResultMessage("Count to what?")
'    End If
'End Sub